local skel = fk.CreateSkill {
  name = "lb_zero__quanyi",
  max_branches_use_time = {
    ["from"] = {
      [Player.HistoryRound] = 1
    },
    ["to"] = {
      [Player.HistoryRound] = 1
    },
  }
}

Fk:loadTranslationTable {
  ["lb_zero__quanyi"] = "拳意",
  [":lb_zero__quanyi"] = "每轮各限一次，当你不因【决斗】使用牌指定或成为其他角色牌的唯一目标后，你可将此牌改为【决斗】，此牌结算完成前，你与此牌花色相同的牌均视为【杀】且你【杀】的打出改为对其使用。",

  ["#lb_zero__quanyi"] = "拳意：你可将 %arg 改为【决斗】",

  ["@@lb_zero__quanyi-inhand"] = "拳意",

  ["$lb_zero__quanyi1"] = "接下来会有点暴力。",
  ["$lb_zero__quanyi2"] = "都看清楚了吗！",
  ["$lb_zero__quanyi3"] = "唯有胜者会被铭记。",
}

local quanyi_spec = {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(skel.name) and target == player and data:isOnlyTarget(data.to) and data.card.name ~= "duel" then
      if event == fk.TargetSpecified then
        return data.to ~= player and skel:withinBranchTimesLimit(player, "from", Player.HistoryRound)
        and (not data.use.responseToEvent or data.use.responseToEvent.card.name ~= "duel")
      else
        return data.from ~= player and skel:withinBranchTimesLimit(player, "to", Player.HistoryRound)
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askToSkillInvoke(player,
      { skill_name = skel.name, prompt = "#lb_zero__quanyi:::" .. data.card:toLogString() })
  end,
  on_use = function(self, event, target, player, data)
    player:addSkillBranchUseHistory(skel.name, event == fk.TargetSpecified and "from" or "to")
    data:changeCard("duel")
    data.extra_data = data.extra_data or {}
    data.extra_data.lb_zero__quanyi_duel = {player.id}
    if not table.contains(player:getTableMark("lb_zero__quanyi-phase"), data.card.suit) then
      player.room:addTableMark(player, "lb_zero__quanyi-phase", data.card.suit)
      data.extra_data.lb_zero__quanyi_slash = {player.id, data.card.suit}
      player:filterHandcards()
    end
  end,
}

skel:addEffect(fk.TargetSpecified, quanyi_spec, { check_skill_limit = true})
skel:addEffect(fk.TargetConfirmed, quanyi_spec, { check_skill_limit = true})

skel:addEffect(fk.CardEffecting, {
  global = true,
  can_refresh = function(self, event, target, player, data)
    return data.extra_data and data.extra_data.lb_zero__quanyi_duel
  end,
  on_refresh = function(self, event, target, player, data)
    data:changeCardSkill("lb_zero__quanyi_duel_skill")
  end,
})

skel:addEffect(fk.CardUseFinished, {
  global = true,
  can_refresh = function(self, event, target, player, data) -- 愿天堂没有嵌套
    return data.extra_data and data.extra_data.lb_zero__quanyi_slash 
    and type(data.extra_data.lb_zero__quanyi_slash) == "table"
    and data.extra_data.lb_zero__quanyi_slash[1] == player.id
    and table.contains(player:getTableMark("lb_zero__quanyi-phase"), data.extra_data.lb_zero__quanyi_slash[2])
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:removeTableMark(player, "lb_zero__quanyi-phase", data.extra_data.lb_zero__quanyi_slash[2])
    player:filterHandcards()
  end,
})

skel:addEffect("filter", {
  mute = true,
  global = true,
  card_filter = function(self, card, player)
    return table.contains(player:getTableMark("lb_zero__quanyi-phase"), card.suit)
  end,
  view_as = function(self, player, card)
    return Fk:cloneCard("slash", card.suit, card.number)
  end,
})

return skel